
package ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.Html;
import android.text.Spanned;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.facebook.drawee.view.SimpleDraweeView;

import net.ck.hzq.R;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import Bean.MPOSBean;
import base.BaseViewHolder;
import base.SuperBaseAdapter;
import coom.Constants;
import ui.activity.home.NewProductAct;
import util.StringUtils;


/**
 * 排行榜适配器
 * Created by chenjian on 19/2/27.
 */
public class PosAdapter extends SuperBaseAdapter<MPOSBean.ChildrenBean.PosModelsBean> {

    List<MPOSBean.ChildrenBean.PosModelsBean> mData = new ArrayList<>();
    Context mContext;

    DecimalFormat df = new DecimalFormat("0.00%");

    public PosAdapter(Context context, List<MPOSBean.ChildrenBean.PosModelsBean> data) {
        super(context, data);
        mContext = context;
        mData = data;
    }

    @Override
    protected void convert(BaseViewHolder holder, final MPOSBean.ChildrenBean.PosModelsBean item, final int position) {
        ImageView imageView = holder.getView(R.id.girdviewpickupmachine_img);
//        imageView.setImageURI(Uri.parse(item.getImgPath()));
        Glide.with(mContext).load(Uri.parse(item.getImgPath())).into(imageView);
        if (item.getCategoryId().equals("4")) {
            //智能机
            holder.getView(R.id.gridviewpickup_text3).setVisibility(View.GONE);
            holder.setText(R.id.gridviewpickup_text1, item.getName() + "")
                    .setText(R.id.gridviewpickup_text2, item.getSellName() + "")
                    .setText(R.id.gridviewpickup_text7, "返代理商" + item.getReturnAmount() + "元/台")
                    .setText(R.id.gridviewpickup_text4, item.getFreezeDesc() + "")
                    .setText(R.id.gridviewpickup_text6, "¥ " + item.getPrice())
                    .setText(R.id.gridviewpickup_text5, item.getActTimeDesc());
        } else if (item.getCategoryId().equals("3")) {
            //购机返押金
            String info = item.getBackDesc() + (StringUtils.isEmpty(item.getActiveDesc()) ? "" : "(" + "<font color=#FF4040 >" + item.getActiveDesc() + "</font>" + ")");
            Spanned str = Html.fromHtml(info);
            holder.getView(R.id.gridviewpickup_text3).setVisibility(View.GONE);
//            String info2 = "首次" + "<font color=#FF4040 >发货" + item.getSingleShipPurchase() + "</font>" + ", 激活" + item.getAfterActivation() + "后发余货";
//            Spanned str2 = Html.fromHtml(info2);
            holder.setText(R.id.gridviewpickup_text1, item.getName() + "")
                    .setText(R.id.gridviewpickup_text2, item.getSellName() + "")
//                    .setText(R.id.gridviewpickup_text3, str2)
                    .setText(R.id.gridviewpickup_text4, item.getFreezeDesc())
                    .setText(R.id.gridviewpickup_text7, str)
                    .setText(R.id.gridviewpickup_text5, item.getActTimeDesc())
                    .setText(R.id.gridviewpickup_text6, "¥ " + item.getPrice());
        } else if (item.getCategoryId().equals("2")) {
            //循环送
            String info = "<font color=#FF4040 >" + item.getActiveDesc() + "</font>";
            Spanned str = Html.fromHtml(info);
            holder.setText(R.id.gridviewpickup_text1, item.getName() + "")
                    .setText(R.id.gridviewpickup_text2, item.getSellName() + "")
                    .setText(R.id.gridviewpickup_text3, item.getDescription())
                    .setText(R.id.gridviewpickup_text4, item.getFreezeDesc())
                    .setText(R.id.gridviewpickup_text7, str)
                    .setText(R.id.gridviewpickup_text5, item.getActTimeDesc())
                    .setText(R.id.gridviewpickup_text6, "¥ " + item.getPrice());

        } else if (item.getCategoryId().equals("9")) {
            //立刷
            String info = item.getBackDesc() + (StringUtils.isEmpty(item.getActiveDesc()) ? "" : "(" + "<font color=#FF4040 >" + item.getActiveDesc() + "</font>" + ")");
            Spanned str = Html.fromHtml(info);
            holder.getView(R.id.gridviewpickup_text3).setVisibility(View.GONE);
//            String info2 = "首次" + "<font color=#FF4040 >发货" + item.getSingleShipPurchase() + "</font>" + ", 激活" + item.getAfterActivation() + "后发余货";
//            Spanned str2 = Html.fromHtml(info2);
            holder.setText(R.id.gridviewpickup_text1, item.getName() + "")
                    .setText(R.id.gridviewpickup_text2, item.getSellName() + "")
//                    .setText(R.id.gridviewpickup_text3, str2)
                    .setText(R.id.gridviewpickup_text4, item.getFreezeDesc())
                    .setText(R.id.gridviewpickup_text7, str)
                    .setText(R.id.gridviewpickup_text5, item.getActTimeDesc())
                    .setText(R.id.gridviewpickup_text6, "¥ " + item.getPrice());
        } else {
            //购机返押金
            String info = item.getBackDesc() + (StringUtils.isEmpty(item.getActiveDesc()) ? "" : "(" + "<font color=#FF4040 >" + item.getActiveDesc() + "</font>" + ")");
            Spanned str = Html.fromHtml(info);
            holder.getView(R.id.gridviewpickup_text3).setVisibility(View.GONE);
//            String info2 = "首次" + "<font color=#FF4040 >发货" + item.getSingleShipPurchase() + "</font>" + ", 激活" + item.getAfterActivation() + "后发余货";
//            Spanned str2 = Html.fromHtml(info2);
            holder.setText(R.id.gridviewpickup_text1, item.getName() + "")
                    .setText(R.id.gridviewpickup_text2, item.getSellName() + "")
//                    .setText(R.id.gridviewpickup_text3, str2)
                    .setText(R.id.gridviewpickup_text4, item.getFreezeDesc())
                    .setText(R.id.gridviewpickup_text7, str)
                    .setText(R.id.gridviewpickup_text5, item.getActTimeDesc())
                    .setText(R.id.gridviewpickup_text6, "¥ " + item.getPrice());
        }
        holder.getView(R.id.gridviewpickupmachine_linear).setOnClickListener(v -> {
            Intent intent = new Intent(mContext, NewProductAct.class);
            intent.putExtra(Constants.KEYSTRING, item.getId());
            mContext.startActivity(intent);

        });
    }


    @Override
    protected int getItemViewLayoutId(int position, MPOSBean.ChildrenBean.PosModelsBean item) {
        return R.layout.gridviewpickupmachine_item;
    }

}
